package com.masterclient.app.businessmodule.minemodule.redpack.adapter;

import android.graphics.Paint;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.masterclient.app.R;
import com.masterclient.app.modules.income.model.ProfitItem;
import com.masterclient.app.businessmodule.minemodule.point.model.PointExchange;
import com.eoner.baselibrary.utils.Utils;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

public class RedPackedProductAdapter extends BaseQuickAdapter<ProfitItem, BaseViewHolder> {
    private int type;
    public RedPackedProductAdapter() {
        super(R.layout.item_redpacded_product);
        type = 0;
    }
    public RedPackedProductAdapter(int type) {
        super(R.layout.item_redpacded_product);
        this.type = type;
    }
//    private Context context;
//    private List<ProfitItem> profitItems;
//
//
//
//    public IncomeCommissionChildAdapter(Context context, List<ProfitItem> profitItems) {
//        this.context = context;
//        this.profitItems = profitItems;
//    }
//
//    @NonNull
//    //创建新View，被LayoutManager所调用
//    @Override
//    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//        context = parent.getContext();
//        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.income_commission_item_item, parent, false);
//        RecyclerView.ViewHolder viewHolder = new IncomeCommissionChildAdapter.ViewHolder(view);
//        return viewHolder;
//    }

    @Override
    protected void convert(BaseViewHolder helper, ProfitItem profitItem) {
//        GlideUtil.displayImage(mContext, profitItem.getSh_image(), helper.getView(R.id.image), R.mipmap.defaults_1);
        ViewTransformUtil.glideImageView(mContext, profitItem.getSh_image(), helper.getView(R.id.image), new Transformation[]{new CenterCrop(), new RoundedCornersTransformation(ScreenUtils.dp2px(7), 0)}, R.mipmap.defaults);

        LinearLayout ll_tuihuo = helper.getView(R.id.ll_tuihuo);
        TextView earn_account_txt = helper.getView(R.id.earn_account_txt);
        Utils.setDin(earn_account_txt,mContext);
        TextView earn_account_txtunit = helper.getView(R.id.earn_account_txtunit);
        TextView price = helper.getView(R.id.price);
        if ("1".equals(profitItem.getSh_status())) {
            ll_tuihuo.setVisibility(View.GONE);
//            earn_account_txt.setTextColor(0xffdfae73);
//            earn_account_txtunit.setTextColor(0xffdfae73);
        } else {
            ll_tuihuo.setVisibility(View.VISIBLE);
            //earn_account_txt.setTextColor(0x4d000000);
            earn_account_txt.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
            //earn_account_txtunit.setTextColor(0x4d000000);
        }
        if (type == 1) ll_tuihuo.setVisibility(View.GONE);

        String temp = "";
        for (PointExchange.Property p : profitItem.getSh_property()) {
            temp = p.getSh_attribute_label() + " : " + p.getSh_alias_name() + " ";
        }
        helper.setText(R.id.earn_account_txt,("0".equals(profitItem.getSh_profit_amount_type())?"¥":"") + profitItem.getSh_profit_amount())
                .setGone(R.id.earn_account_txt, type == 0)
                .setGone(R.id.earn_account_txtunit,type == 0)
                .setText(R.id.gift_tag,profitItem.getSh_product_type_txt())
                .setGone(R.id.gift_tag, !TextUtils.isEmpty(profitItem.getSh_product_type_txt()))
                .setText(R.id.earn_account_txtunit,"0".equals(profitItem.getSh_profit_amount_type())?"赚":"赚向日葵币")
                .setGone(R.id.double_tag,!TextUtils.isEmpty(profitItem.getSh_double_commission_status())
                        &&"1".equals(profitItem.getSh_double_commission_status()))
                .setText(R.id.sku_desc, temp)
                .setText(R.id.sh_num, "x " + profitItem.getSh_num())
                .setGone(R.id.line, helper.getAdapterPosition() != getData().size()-1)
                .setText(R.id.title, profitItem.getSh_title());
        Utils.setDin(price, mContext);
        Utils.set_goodsdetail_price_style1(price, "¥ " + profitItem.getSh_price());
    }



}


